import { AxiosRequestConfig, AxiosResponse } from '../types'

export class AxiosError extends Error {
  constructor(
    message: string,
    readonly config: AxiosRequestConfig,
    readonly code?: string | null,
    readonly request?: any,
    readonly response?: AxiosResponse,
    readonly isAxiosError = true
  ) {
    super(message)

    Object.setPrototypeOf(this, AxiosError.prototype) // 设置当前对象的原型
  }
}

export function createError(
  message: string,
  config: AxiosRequestConfig,
  code?: string | null,
  request?: any,
  response?: AxiosResponse
): AxiosError {
  return new AxiosError(message, config, code, request, response)
}
